#ifdef ENABLE_NETWORK
#include "KeyBoardEvent.h"
//#include "winselectevent.h"
//#include "WinHomeEvent.h"
//#include "CardMultiUpEvent.h"
#include "net/iwconfig/iwlib.h"
#include "Network_SetupEvent.h"
#include "user.h"
#ifndef IW_ESSID_MAX_SIZE
#define IW_ESSID_MAX_SIZE 32
#endif

#define WHITE_COLOUR 5
INT8U keyboard_parent_flag;//0 menu kodakgallery, 1 menu internet 2 menu Enable 1, 3 menu Enable2
INT8U key_focus_flag=0;
INT8U key_menu_flag;
INT8U key_caps_flag=0;
INT8U key_shift_flag=0;
INT8U string_length_flag=0;
INT8U char_number=40;
INT8U pre_focus_flag=0;
unsigned char output_string[IW_ENCODING_TOKEN_MAX + 1];
#define AW_BLACK_COLOR  3
extern int manu_ap_mode;
extern struct iwscan_state *Scan_Result;
extern char output_point[IW_ESSID_MAX_SIZE + 1];
#include "../aw_network.h"
//4 menu netselect2,5 menu netselect1
static char *ptr;
#include "../aw_sys_app.h"
#include "../aw_config.h"

extern yahoo_login_info_t yahoo_config;
extern google_login_info_t google_config;
extern framechannel_login_info_t framechannel_config;

typedef void (*NetFsBrowserTask_t)(void *opt);
extern unsigned short NetFsBrowserTaskStart(NetFsBrowserTask_t NetFsBrowserTask);
extern INT8U menu_index_process;

#define KEY1_LINE  30
#define KEYX_OFFSET  10
#ifdef ENABLE_NETWORK 
static int icon_pos_y[5]={152,196,240,284,334};
static int icon_pos_x[55]={
	                      36,32+56,32+54*2,29+54*3,26+54*4,23+54*5,21+54*6,18+54*7,15+54*8,13+54*9,10+54*10,7+54*11,4+54*12,1+54*13,  
	                      88,88+54,84+54*2,86+52*3,85+52*4,84+52*5,84+52*6,84+52*7,83+52*8,82+52*9,81+52*10,80+52*11,
	                      42,46+86,128+56,123+56*2,119+56*3,113+56*4,109+56*5,114+54*6,112+54*7,110+54*8,106+54*9,102+54*10,101+54*11,
	                      92,92+92,92+88+56,90+88+54*2,88+88+54*3,84+88+54*4,80+88+54*5,78+88+54*6,76+88+54*7,73+88+54*8,70+88+54*9,67+88+54*10,
	                      98,206 ,556, 644 	                      
	                      };
static int word_pos_y[5]={152+8,196+8,240+8,284+8,328+12};
static int word_pos_x[55]={
	                      36+KEYX_OFFSET,32+56+KEYX_OFFSET,32+54*2+KEYX_OFFSET,    29+54*3+KEYX_OFFSET,  26+54*4+KEYX_OFFSET,    23+54*5+KEYX_OFFSET,   21+54*6+KEYX_OFFSET,   18+54*7+KEYX_OFFSET,   15+54*8+KEYX_OFFSET,   13+54*9+KEYX_OFFSET,  10+54*10+KEYX_OFFSET,   7+54*11+KEYX_OFFSET,4+54*12+KEYX_OFFSET,1+54*13+KEYX_OFFSET,  
	                      88+KEYX_OFFSET,88+54+KEYX_OFFSET,84+54*2+KEYX_OFFSET,    86+52*3+KEYX_OFFSET,  85+52*4+KEYX_OFFSET,    84+52*5+KEYX_OFFSET,   84+52*6+KEYX_OFFSET,   84+52*7+KEYX_OFFSET,   83+52*8+KEYX_OFFSET,   82+52*9+KEYX_OFFSET,  81+52*10+KEYX_OFFSET,   80+52*11+KEYX_OFFSET,
	                      42+KEYX_OFFSET,46+86+KEYX_OFFSET, 128+56+KEYX_OFFSET,   123+56*2+KEYX_OFFSET,  119+56*3+KEYX_OFFSET,  113+56*4+KEYX_OFFSET,  109+56*5+KEYX_OFFSET,  114+54*6+KEYX_OFFSET,  112+54*7+KEYX_OFFSET,  110+54*8+KEYX_OFFSET,  106+54*9+KEYX_OFFSET,  102+54*10+KEYX_OFFSET,101+54*11+KEYX_OFFSET,
	                      92+KEYX_OFFSET,92+92+KEYX_OFFSET,92+88+56+KEYX_OFFSET,90+88+54*2+KEYX_OFFSET,88+88+54*3+KEYX_OFFSET,84+88+54*4+KEYX_OFFSET,80+88+54*5+KEYX_OFFSET,78+88+54*6+KEYX_OFFSET,76+88+54*7+KEYX_OFFSET,73+88+54*8+KEYX_OFFSET,70+88+54*9+KEYX_OFFSET,67+88+54*10+KEYX_OFFSET, 
	                      100+16,206+130,564+18, 634+29	                      
	                      };

#else

static int icon_pos_y[5]={232,272,312,352,392};
static int icon_pos_x[55]={
	                      2,2+56,2+56*2,2+56*3,2+56*4,2+56*5,2+56*6,2+56*7,2+56*8,2+56*9,2+56*10,2+56*11,2+56*12,2+56*13,
	                      58,58+56,58+56*2,58+56*3,58+56*4,58+56*5,58+56*6,58+56*7,58+56*8,58+56*9,58+56*10,58+56*11,
	                      27,27+66,93+56,93+56*2,93+56*3,93+56*4,93+56*5,93+56*6,93+56*7,93+56*8,93+56*9,93+56*10,93+56*11,
	                      52,52+66,52+66+56,52+66+56*2,52+66+56*3,52+66+56*4,52+66+56*5,52+66+56*6,52+66+56*7,52+66+56*8,52+66+56*9,52+66+56*10,
	                      90,206 ,554, 624 	                      
	                      };
static int word_pos_y[5]={232+8,272+8,312+8,352+8,392+8};
static int word_pos_x[55]={
	                      2+10,2+56+10,2+56*2+10,2+56*3+10,2+56*4+10,2+56*5+10,2+56*6+10,2+56*7+10,2+56*8+10,2+56*9+10,2+56*10+10,2+56*11+10,2+56*12+10,2+56*13+10,
	                      58+10,58+56+10,58+56*2+10,58+56*3+10,58+56*4+10,58+56*5+10,58+56*6+10,58+56*7+10,58+56*8+10,58+56*9+10,58+56*10+10,58+56*11+10,
	                      27+8,93+10,93+56+10,93+56*2+10,93+56*3+10,93+56*4+10,93+56*5+10,93+56*6+10,93+56*7+10,93+56*8+10,93+56*9+10,93+56*10+10,93+56*11+10,
	                      52+8,52+66+10,52+66+56+10,52+66+56*2+10,52+66+56*3+10,52+66+56*4+10,52+66+56*5+10,52+66+56*6+10,52+66+56*7+10,52+66+56*8+10,52+66+56*9+10,52+66+56*10+10,
	                      90+8,206+130,554+8, 624+8	                      
	                      };

#endif
static char key_word[55][6]={
										"  `  ","  1  ","  2  ","  3  ","  4  ","  5  ","  6  ","  7  ","  8  ","  9  ","  0  ","  -  ","  =  ","  <-",
										"  q  ","  w  ","  e  ","  r  ","  t  ","  y  ","  u  ","  i  ","  o  ","  p  ","  [  ","  ]  ",
										"Lock ","  a  ","  s  ","  d  ","  f  ","  g  ","  h  ","  j  ","  k  ","  l  ","  ;  ","  '  ","    ",
										"Shift","  z  ","  x  ","  c  ","  v  ","  b  ","  n  ","  m  ","  ,  ","  .  ","  /  ","  @  ",
										"Clear","SPACE","Done","Back"
                    };
static char key_word_caps[55][6]={
										"  ~  ","  !  ","  @  ","  #  ","  $  ","  %  ","  ^  ","  &  ","  *  ","  (  ","  )  ","  _  ","  +  ","  <-",
										"  Q  ","  W  ","  E  ","  R  ","  T  ","  Y  ","  U  ","  I  ","  O  ","  P  ","  {  ","  }  ",
										"Lock ","  A  ","  S  ","  D  ","  F  ","  G  ","  H  ","  J  ","  K  ","  L  ","  :  ","     ","  |  ",
										"Shift","  Z  ","  X  ","  C  ","  V  ","  B  ","  N  ","  M  ","  <  ","  >  ","  ?  ","  @  ",
										"Clear","SPACE","Done","Back"
                    };
//void KgLogOffTask(void* arg);
INT8U GetPos_y(INT8U x)
{
	if(x<14)
		return 0;
	else if(x<26)
		return 1;
	else if(x<39)
		return 2;
	else if(x<51)
		return 3;
	else if(x<55)
		return 4;
	}
void GetKeyBoardFocus(PHWND hwnd)
{   
	switch(key_focus_flag) 
	{
		case 52:
			hwnd->draw_info[3].draw_data = (INT32U)ICON_KEYBOARD_SPC;
    	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
      hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
      break;
     case 39:
     case 53:
     case 54:	
     case 51:
     case 26:
     	hwnd->draw_info[2].draw_pos_x=icon_pos_x[key_focus_flag];
     	hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(key_focus_flag)];
     	hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_FOUR;
    	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
      hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
      break;
     default:
     	hwnd->draw_info[2].draw_pos_x=icon_pos_x[key_focus_flag];
     	hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(key_focus_flag)];
     	hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_ONE;
    	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
      hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
      break;     	     	
	}
		 	if((key_caps_flag==0)&&(key_shift_flag==0))
	 		  AWAsciiPrintf(word_pos_x[key_focus_flag], word_pos_y[GetPos_y(key_focus_flag)], key_word[key_focus_flag]) ;
	 		else 
	 		  AWAsciiPrintf(word_pos_x[key_focus_flag], word_pos_y[GetPos_y(key_focus_flag)], key_word_caps[key_focus_flag]) ;          	  		
}
void GetKeyBoardLose(PHWND hwnd)
{
	switch(pre_focus_flag)
	{
		case 52:
			hwnd->draw_info[3].draw_data = (INT32U)ICON_KEYBOARD_SPC_LOSE;
    	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
      hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
      break;
     case 39:
     case 53:
     case 54:	
     case 51:
     case 26:
     	  hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_FOUR_LOSE;
    		hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
        hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
        break;
      default:
      	hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_ONE_LOSE;
    		hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
        hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
        break;
	}
		 	if((key_caps_flag==0)&&(key_shift_flag==0))
	 		  AWAsciiPrintf(word_pos_x[pre_focus_flag], word_pos_y[GetPos_y(pre_focus_flag)], key_word[pre_focus_flag]) ;
	 		else 
	 		  AWAsciiPrintf(word_pos_x[pre_focus_flag], word_pos_y[GetPos_y(pre_focus_flag)], key_word_caps[pre_focus_flag]) ; 
 
}
void KeyBoardDonePressEnter(PHWND hwnd)
{ 
	PHWND dir_hwnd=AWFindWinCtrlByName("KeyBoardCaption");
	int i;
	switch(key_menu_flag)
	{
	case ID_MENU_MANUAL_URL:   //internet manual  URL
    	
    	/* Manual internet configure, input URL case */
		strncpy(output_point, (char *)output_string, RSS_MAX_USENAME_LEN);
		if(menu_index_process==ID_INTERNET_YAHOO_SETTING)
		{
			memset(internet_setting[0],0,sizeof(internet_setting[0]));
			memset(yahoo_config.username,0,sizeof(yahoo_config.username));
			strncpy(internet_setting[0],(char *)output_string,RSS_MAX_USENAME_LEN);
			strncpy(yahoo_config.username,internet_setting[0],strlen(internet_setting[0]));
			SetYahooConfig(&yahoo_config); 
		}
		else if(menu_index_process==ID_INTERNET_GOOGLE_SETTING)
        {
			memset(internet_setting[2],0,sizeof(internet_setting[2]));
			memset(google_config.username,0,sizeof(google_config.username));
			strncpy(internet_setting[2],(char *)output_string,RSS_MAX_USENAME_LEN);
			strncpy(google_config.username,internet_setting[2],strlen(internet_setting[2]));			
			SetGoogleConfig(&google_config);  
        }
		else if(menu_index_process==ID_INTERNET_FRAME_CHNL_SETTING)
		{
			memset(internet_setting[4], 0, sizeof(internet_setting[4]));
			memset(framechannel_config.username, 0, sizeof(framechannel_config.username));
			strncpy(internet_setting[4], (char *)output_string, RSS_MAX_USENAME_LEN);
			strncpy(framechannel_config.username, internet_setting[4], strlen(internet_setting[4]));			
//			SetFrameChannelConfig(&framechannel_config);
        }

		GUIShowWindow("Network_Setup");    	
		break;
    	
	case ID_MENU_MANUAL_PASSWORD: //internet manual password
        /* Manual internet configure, input PASSWORD case */
		strncpy(output_point, (char *)output_string, IW_ESSID_MAX_SIZE);   	

		if (menu_index_process == ID_INTERNET_YAHOO_SETTING)
		{
			Keyboard_str[string_length_flag] = '\0';
			memset(internet_setting[1], 0, sizeof(internet_setting[1]));
			strncpy(internet_setting[1], (char *)Keyboard_str, RSS_MAX_PASSPHRASE_LEN);			
			memset(yahoo_config.passphrase, 0, sizeof(yahoo_config.passphrase));
			strncpy(yahoo_config.passphrase, (char *)output_string, RSS_MAX_PASSPHRASE_LEN);
			//yahoo_config.passphrase[RSS_MAX_PASSPHRASE_LEN] = '\0';

			SetYahooConfig(&yahoo_config);
		}
		else if (menu_index_process == ID_INTERNET_GOOGLE_SETTING)
		{
			Keyboard_str[string_length_flag] = '\0';	
			memset(internet_setting[3], 0, sizeof(internet_setting[3]));
			strncpy(internet_setting[3], (char *)Keyboard_str, RSS_MAX_PASSPHRASE_LEN);			
			memset(google_config.passphrase, 0, sizeof(google_config.passphrase));
			strncpy(google_config.passphrase, (char *)output_string, RSS_MAX_PASSPHRASE_LEN);
			//google_config.passphrase[RSS_MAX_PASSPHRASE_LEN] = '\0';

			SetGoogleConfig(&google_config);
		}
		else if (menu_index_process == ID_INTERNET_FRAME_CHNL_SETTING)
		{
			Keyboard_str[string_length_flag] = '\0';	
			memset(internet_setting[5], 0, sizeof(internet_setting[5]));
			strncpy(internet_setting[5], (char *)Keyboard_str, RSS_MAX_PASSPHRASE_LEN);			
			
			memset(framechannel_config.passphrase, 0, sizeof(framechannel_config.passphrase));
			strncpy(framechannel_config.passphrase, (char *)output_string, RSS_MAX_PASSPHRASE_LEN);
			//framechannel_config.passphrase[RSS_MAX_PASSPHRASE_LEN] = '\0';

//			SetFrameChannelConfig(&framechannel_config);
        }

		GUIShowWindow("Network_Setup");   	
		break; 
   	
	case ID_MENU_MANUAL_SSID://SSID
        /* Manual network configure, input SSID case */
			strncpy(output_point, (char *)output_string, IW_ESSID_MAX_SIZE);

			/* Save SSID name. */
			strncpy(aml_wireless_config.essid, output_point, IW_ESSID_MAX_SIZE);
			string_length_flag=0;
			//PresetMenuNetSelect();
            //SetSSIDPara((unsigned char *)output_point);
			memset(APNAME_STR[0],0,sizeof(APNAME_STR[0]));
			strncpy(APNAME_STR[0],(char *)output_string,IW_ESSID_MAX_SIZE);      
        
			GUIShowWindow("Network_Setup");		
			
		break;
        
	case ID_MENU_MANUAL_WEP://WEP
        /* Manual network configure, input WEP case */
		Keyboard_str[string_length_flag] = '\0';
		char wep_string[14];
		i = WEP_key_Verify((char *)output_string, string_length_flag,wep_string);
		if (i)
		{
            /* Save WEP key. */
			// memcpy(aml_wireless_config.key, output_string, i);
			memcpy(aml_wireless_config.key, wep_string, i);
			aml_wireless_config.key_len = i;
			aml_wireless_config.security = IW_SECURITY_WEP;

			// PresetMenuEnable(ID_MENU_WEP_WPA);
			GUIShowWindow("Network_Setup");
			string_length_flag=0;
		}
		else
		{
            /* Invalid WEP key entered. */
			Keyboard_str[string_length_flag]='|';
		}

		break;
	case ID_MENU_MANUAL_WPA://WPA
        /* Manual network configure, input WPA case */
		Keyboard_str[string_length_flag] = '\0';

		if (string_length_flag < 8) {
            /* Minimum 8 ASCII characters for WPA passphrase. */
		Keyboard_str[string_length_flag]='|';
		}
		else {
            /* Save WPA key. */
			aml_wireless_config.security = IW_SECURITY_WPA;
			aml_wireless_config.key_len = strlen( (char *)output_string);
			memcpy(aml_wireless_config.key,  (char *)output_string, aml_wireless_config.key_len);

			// PresetMenuEnable(ID_MENU_WEP_WPA);
			GUIShowWindow("Network_Setup");
			string_length_flag=0;
		}
		break;
	case ID_MENU_MANUALLY_ENTER_SSID://SSID connect
        /* Wireless scan -> no AP found, manual enter AP case */
		strncpy(output_point, (char *)output_string, IW_ESSID_MAX_SIZE);
		
		/* Save SSID name. */
		strncpy(aml_wireless_config.essid, output_point, IW_ESSID_MAX_SIZE);

        /** 
         *  The following check will always fail since we did *NOT* detect the AP
         *  during wireless scan.
         *
         *  So how does user input WEP/WPA information in this case???
         */
		int ret = Get_Security_Setting(Scan_Result, output_point);
		if(ret)
		{
            //PresetMenuEnable(ID_MENU_SECURITY_KEYBOARD_WEP_WPA);
            //GUIShowWindow("WinSelect");           
			if(ret == IW_SECURITY_WEP){
				key_menu_flag=ID_MENU_SECURITY_WEP;
			}else if(ret == IW_SECURITY_WPA){
				key_menu_flag=ID_MENU_SECURITY_WPA;
			}else if(ret == IW_SECURITY_WPA2){
				key_menu_flag=ID_MENU_SECURITY_WPA;
			}	                
			//GUIHideWindow("WinKeyBoard");	
			keyboard_parent_flag=8;
			//GUIShowWindow("WinKeyBoard");	
			KeyControlBarOnShow(hwnd,0);
			AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1) ;
			AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 4) ;
			AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;
			KeyBoardCaptionOnShow(dir_hwnd,0);
			AWPostMessage(dir_hwnd, WM_PAINT, 0) ;
			//AWPostMessage(dir_hwnd, WM_PAINT_DRAW_INFO, 1) ;
			//AWPostMessage(dir_hwnd, WM_PAINT_FINISH, 0) ;	
	
			//iw_free_scan_list(Scan_Result);
			// Scan_Result = NULL;
		}
		else
		{
			Start_Connect(&aml_wireless_config);
			//PresetMenuProcess_Info(ID_MENU_INFO_CONNECTING);
			//change_warning_message(ID_MENU_INFO_CONNECTING);
			menu_index_process=ID_MENU_INFO_CONNECTING;
			GUIShowWindow("WinWarnMessageBox");
            
			//repaint_message();		            
		}

		// SetSSIDPara((unsigned char *)output_point);
		break;
	case ID_MENU_SECURITY_WEP://WEP security
        /* Wireless scan -> select AP -> enter WEP case */
		Keyboard_str[string_length_flag]='\0';

		char wep_menu_string[14];
		i = WEP_key_Verify((char *)output_string, string_length_flag,wep_menu_string);
		if (i)
		{
            /* Save SSID name. */
			strncpy(aml_wireless_config.essid, (char *)output_point, IW_ESSID_MAX_SIZE);

            /* Save WEP key. */           
			memcpy(aml_wireless_config.key, &wep_menu_string, i);
			aml_wireless_config.key_len = i;
			aml_wireless_config.security = IW_SECURITY_WEP;
            
			menu_index_process=ID_MENU_SECURITY_WEP;
			GUIShowWindow("WinWarnMessageBox");
			//AVTimeDly(300);
			Start_Connect(&aml_wireless_config);
			// PresetMenuProcess_Info(ID_MENU_INFO_CONNECTING);
			// change_warning_message(ID_MENU_SECURITY_WEP);        
         
			//repaint_message();
            
			string_length_flag=0;
		}
		else
		{
			Keyboard_str[string_length_flag]='|';
		}
		break;
	case ID_MENU_SECURITY_WPA://WPA security
        /* Wireless scan -> select AP -> enter WPA case */
		Keyboard_str[string_length_flag]='\0';

        /* Minimum 8 ASCII characters for WPA passphrase. */
		if (string_length_flag < 8) {
			Keyboard_str[string_length_flag]='|';
		}
		else {
            /* Save SSID name. */
			strncpy(aml_wireless_config.essid, (char *)output_point, IW_ESSID_MAX_SIZE);

            /* Save WPA key. */
			aml_wireless_config.security = IW_SECURITY_WPA;
			aml_wireless_config.key_len = strlen((char *)output_string);           
			memcpy(aml_wireless_config.key, (char *)output_string, aml_wireless_config.key_len);
           
			Start_Connect(&aml_wireless_config);
			//PresetMenuProcess_Info(ID_MENU_INFO_CONNECTING);
			menu_index_process=ID_MENU_SECURITY_WPA;
          
			GUIShowWindow("WinWarnMessageBox");
  
			//repaint_message();
			string_length_flag=0;
		}
		break;
        
	case ID_MENU_SET_FRAME_NAME://set frame name
       // SetFrameNamePara((unsigned char *)output_string);
       // PresetMenuTotalSelect(2,ID_MENU_DEVICE_CONFIGURATION_SET);
        //GUIShowWindow("WinSelect");
		break;
	default:
		break;
    }
}

void KeyBoardPressEnter(PHWND hwnd)
{ 
	INT8U i;
	INT32S word_width = 580,font_height, word_len, str_len ;
	switch(key_focus_flag)
	{
		case 13:
			if(string_length_flag==0)
				break;
			string_length_flag--;
			output_string[string_length_flag]='\0';
			Keyboard_str[string_length_flag+1]='\0';
			Keyboard_str[string_length_flag]='|';	
			AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1) ;
	    AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 4) ;
      AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;		
			break;
		case 26:
			key_caps_flag=!key_caps_flag;
			for(i=0;i<55;i++)
			{
				 switch(i)
				 {
				 	case 52:
						 	hwnd->draw_info[3].draw_data = (INT32U)ICON_KEYBOARD_SPC_LOSE;
		    	    hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
		          hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
		          break;
		      case 39:
          case 53:
          case 54:	
          case 51:
          case 26:
      	      hwnd->draw_info[2].draw_pos_x=icon_pos_x[i];
 	            hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(i)];
 	            hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_FOUR_LOSE;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
              hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
              break;
          default:
	          	hwnd->draw_info[2].draw_pos_x=icon_pos_x[i];
	            hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(i)];
	            hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_ONE_LOSE;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
	            break;          			      	
				}
					if((key_caps_flag==0)&&(key_shift_flag==0))
			 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word[i]) ;
			 		else 
			 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word_caps[i]); 						
			}
			GetKeyBoardFocus(hwnd);
			break;
		case 39:
			key_shift_flag=!key_shift_flag;
			for(i=0;i<55;i++)
			{
				 switch(i)
				 {
				 	case 52:
						 	hwnd->draw_info[3].draw_data = (INT32U)ICON_KEYBOARD_SPC_LOSE;
		    	    hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
		          hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
		          break;
		      case 39:
          case 53:
          case 54:	
          case 51:
          case 26:
      	      hwnd->draw_info[2].draw_pos_x=icon_pos_x[i];
 	            hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(i)];
 	            hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_FOUR_LOSE;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
              hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
              break;
          default:
	          	hwnd->draw_info[2].draw_pos_x=icon_pos_x[i];
	            hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(i)];
	            hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_ONE_LOSE;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
	            break;          			      	
				}
					if((key_shift_flag==0)&&(key_caps_flag==0))
			 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word[i]) ;
			 		else 
			 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word_caps[i]); 						
			}
			GetKeyBoardFocus(hwnd);
			break;
		case 51:
			string_length_flag=0;
			memset(output_string,0,sizeof(output_string));
	    memset(Keyboard_str,0,sizeof(Keyboard_str));
	    Keyboard_str[0]='|';
			AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1) ;
	    AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 4) ;
      AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;	
      break;
     case 52:
	    str_len = AWGetTextSize(Keyboard_str, 0,&word_width,&font_height,&word_len, AWTF_ASCII) ;
     	if(string_length_flag>str_len)
     		break;
     	string_length_flag++;
     	output_string[string_length_flag-1]=' ';
     	if((key_menu_flag==ID_MENU_KODAKGALLERY_PASSWORD)||(key_menu_flag==ID_MENU_MANUAL_WEP)||(key_menu_flag==ID_MENU_MANUAL_WPA)||(key_menu_flag==ID_MENU_SECURITY_WEP)||(key_menu_flag==ID_MENU_SECURITY_WPA)||(key_menu_flag==ID_MENU_MANUAL_PASSWORD))
     	  Keyboard_str[string_length_flag-1]='*';
     	else
     		Keyboard_str[string_length_flag-1]=' ';
     	Keyboard_str[string_length_flag]='|';
     	AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1) ;
	    AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 4) ;
      AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;	
      break;
     case 53:
     	output_string[string_length_flag]='\0';
     	KeyBoardDonePressEnter(hwnd);
     	break;
     case 54:
     
     	 GUIShowWindow("Network_Setup");
     	break;
     		
     default:
	 	  str_len = AWGetTextSize(Keyboard_str, 0,&word_width,&font_height,&word_len, AWTF_ASCII) ;
     	  if(string_length_flag>str_len)
     		break;
     	string_length_flag++;
     	if((key_caps_flag==0)&&(key_shift_flag==0))
     		{
	     	output_string[string_length_flag-1]=key_word[key_focus_flag][2];
	 if((key_menu_flag==ID_MENU_KODAKGALLERY_PASSWORD)||(key_menu_flag==ID_MENU_MANUAL_WEP)||(key_menu_flag==ID_MENU_MANUAL_WPA)||(key_menu_flag==ID_MENU_SECURITY_WEP)||(key_menu_flag==ID_MENU_SECURITY_WPA)||(key_menu_flag==ID_MENU_MANUAL_PASSWORD))
     	    Keyboard_str[string_length_flag-1]='*';
      	else
	      	Keyboard_str[string_length_flag-1]=key_word[key_focus_flag][2];
	    }
     	else
     	{
     		output_string[string_length_flag-1]=key_word_caps[key_focus_flag][2];
     	if((key_menu_flag==ID_MENU_KODAKGALLERY_PASSWORD)||(key_menu_flag==ID_MENU_MANUAL_WEP)||(key_menu_flag==ID_MENU_MANUAL_WPA)||(key_menu_flag==ID_MENU_SECURITY_WEP)||(key_menu_flag==ID_MENU_SECURITY_WPA)||(key_menu_flag==ID_MENU_MANUAL_PASSWORD))
     	   Keyboard_str[string_length_flag-1]='*';
      	else
     	   Keyboard_str[string_length_flag-1]=key_word_caps[key_focus_flag][2];
      }
     	Keyboard_str[string_length_flag]='|';
     	if(key_shift_flag==1)
     		{
     			key_shift_flag=0;
     			for(i=0;i<55;i++)
			{
				 switch(i)
				 {
				 	case 52:
						 	hwnd->draw_info[3].draw_data = (INT32U)ICON_KEYBOARD_SPC_LOSE;
		    	    hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
		          hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
		          break;
		      case 39:
          case 53:
          case 54:	
          case 51:
          case 26:
      	      hwnd->draw_info[2].draw_pos_x=icon_pos_x[i];
 	            hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(i)];
 	            hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_FOUR_LOSE;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
              hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
              break;
          default:
	          	hwnd->draw_info[2].draw_pos_x=icon_pos_x[i];
	            hwnd->draw_info[2].draw_pos_y=icon_pos_y[GetPos_y(i)];
	            hwnd->draw_info[2].draw_data = (INT32U)ICON_KEYBOARD_ONE_LOSE;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
	            hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
	            break;          			      	
				}   
			if((key_caps_flag==0)&&(key_shift_flag==0))
	 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word[i]) ;
	 		 else 
	 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word_caps[i]) ;						
			}
			GetKeyBoardFocus(hwnd);
     		}
     	AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1) ;
	    AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 4) ;
      AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;	
      break;     		     	     	     	     				
	}
	
}
INT32S KeyControlBarOnShow(PHWND hwnd, INT32S lpParam)
{    
   // INT8U i;
    INT32S word_width = 580,font_height, word_len, str_len ;
    memset(output_string,0,sizeof(output_string));
    memset(Keyboard_str,0,sizeof(Keyboard_str));
    Keyboard_str[0]='|';
    string_length_flag=0;
    key_word[38][2]=92;
    key_word_caps[37][2]=34;
    key_focus_flag=0;
    GetKeyBoardLose(hwnd);
    GetKeyBoardFocus(hwnd);
    pre_focus_flag=key_focus_flag;
    
    switch(key_menu_flag)
    {
   	case ID_MENU_MANUAL_URL:
        /* Use the current URL name in kodak_wirelss_config */	
        if(menu_index_process==ID_INTERNET_YAHOO_SETTING)
    	{
    	 	ptr = yahoo_config.username;
        	string_length_flag=strlen(ptr);
        	strcpy(Keyboard_str,ptr);
        	strcpy((char *)output_string,ptr);
        	Keyboard_str[string_length_flag]='|';	
        }
        else if(menu_index_process==ID_INTERNET_GOOGLE_SETTING)
    	{
    		ptr = google_config.username;
        	string_length_flag=strlen(ptr);
        	strcpy(Keyboard_str,ptr);
        	strcpy((char *)output_string,ptr);
        	Keyboard_str[string_length_flag]='|';
        }
        else if(menu_index_process == ID_INTERNET_FRAME_CHNL_SETTING)
        {
            ptr = framechannel_config.username;
            string_length_flag = strlen(ptr);
            strcpy(Keyboard_str, ptr);
            strcpy((char *)output_string, ptr);
            Keyboard_str[string_length_flag] = '|';
        }
        break;
   		
   	case ID_MENU_MANUAL_SSID:
   	case ID_MENU_MANUALLY_ENTER_SSID:
        /* Use the current SSID name in kodak_wirelss_config */
        ptr = aml_wireless_config.essid;
        string_length_flag=strlen(ptr);
        strcpy(Keyboard_str,ptr);
        strcpy((char *)output_string,ptr);
        Keyboard_str[string_length_flag]='|';
        break; 
    case ID_MENU_SET_FRAME_NAME:
       // ptr=(char *)GetFrameNamePara();
       	string_length_flag=strlen(ptr);
        strcpy(Keyboard_str,ptr);
        strcpy((char *)output_string,ptr);
        Keyboard_str[string_length_flag]='|';
        break;
    }
	  str_len = AWGetTextSize(Keyboard_str, 0,&word_width,&font_height,&word_len, AWTF_ASCII) ;
	  Keyboard_str[str_len+1]=0;
    return 0 ;
}
INT32S KeyControlBarOnKeyPress(PHWND hwnd, INT32S lpParam)
{  
	PHWND dir_hwnd = AWFindWinCtrlByName("KeyBoardCaption");

	  INT32U *key_value = (INT32U *)lpParam ;
	  if( *key_value==UOP_OSD)
		 GUIShowWindow("WinHome");
		 switch(*key_value)
		 {
		 	case UOP_RESUME:
			case UOP_STOP:
		 		switch(keyboard_parent_flag)
		 	{
		 		case 0:
		 	   //PresetMenuKodakGallery();
		     GUIShowWindow("Network_Setup");
		     break;
		    case 1:
		//    	PresetMenuInternet();
		    	GUIShowWindow("Network_Setup");
		    	break;
		    case 3:
		//    		PresetMenuEnable(ID_MENU_WEP_WPA);
		    	 GUIShowWindow("Network_Setup");
		    	break;
		    case 4:
		//    	PresetMenuNetSelect();
		    	GUIShowWindow("Network_Setup");
		     break;
		    case 5:
		//     	PresetMenuNetSelect();
		     	GUIShowWindow("Network_Setup");
		     	break;
		     case 6:
		//     	PresetMenuConnect(ID_MENU_NO_WIRELESS_NETWORK);
          GUIShowWindow("Network_Setup");
		     	break;
		     case 7:
		//     	PresetMenuNotOnShown(ID_MENU_NETWORK_NOT_ONSHOW);
          GUIShowWindow("Network_Setup");
		     	break;
		     case 8:
		     	//PresetMenuEnable(ID_MENU_SECURITY_WEP_WPA);
		     	//GUIShowWindow("WinSelect");
		     	//GUIHideWindow("WinKeyBoard");	
			key_menu_flag=ID_MENU_MANUALLY_ENTER_SSID;
	     		keyboard_parent_flag=7;
	     		KeyControlBarOnShow(hwnd,0);
	     		AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 1) ;
	     		AWPostMessage(hwnd, WM_PAINT_DRAW_INFO, 4) ;
      	     		AWPostMessage(hwnd, WM_PAINT_FINISH, 0) ;
	     		KeyBoardCaptionOnShow(dir_hwnd,0);
	     		AWPostMessage(dir_hwnd, WM_PAINT, 0) ;
	     		//GUIShowWindow("WinKeyBoard");
		     	break;
         case 9:
//         	PresetMenuTotalSelect(2,ID_MENU_DEVICE_CONFIGURATION_SET);
          GUIShowWindow("Network_Setup");
         	break;
	  case 10:
	  	//GUIShowWindow("Windialog");
	  	GUIShowWindow("Network_Setup");
		break;
          default:
          	GUIShowWindow("Network_Setup");
          	break;
		  }
		 		break;
		 	case UOP_ENTER:
		 		KeyBoardPressEnter(hwnd);
		 		break;
		 	case UOP_LEFT:
		 		if(key_focus_flag==0)
		 			break;
		 			key_focus_flag--;
		 			GetKeyBoardLose(hwnd);
		 			GetKeyBoardFocus(hwnd);
		 			pre_focus_flag=key_focus_flag;
		 	    break;
		 	case UOP_RIGHT:
		 		if(key_focus_flag==54)
		 			break;
		 			key_focus_flag++;
		 			GetKeyBoardLose(hwnd);
		 			GetKeyBoardFocus(hwnd);
		 			pre_focus_flag=key_focus_flag;
		 	 	break;
		 	case UOP_DOWN:
		 		if(key_focus_flag>50)
		 			break;
		 		else if(key_focus_flag==50)
		 			key_focus_flag=53;
		 		else if(key_focus_flag>39)
		 			key_focus_flag=52;
		 		else if(key_focus_flag==39)
		 			key_focus_flag=51;	 		
		 		else if(key_focus_flag>26)
		 			key_focus_flag+=12;
		 		else if(key_focus_flag==26)
		 			key_focus_flag=39;
		 		else if(key_focus_flag>13)
		 			key_focus_flag+=12;
		 		else if(key_focus_flag>11)
		 			key_focus_flag=25;
		 		else if(key_focus_flag>0)
		 			key_focus_flag+=13;
		 		else
		 			key_focus_flag=14;
		 			GetKeyBoardLose(hwnd);
		 			GetKeyBoardFocus(hwnd);
		 			pre_focus_flag=key_focus_flag;
		 		break;
		 	case UOP_UP:
		 		if(key_focus_flag<14)
		 			break;
		 		else if(key_focus_flag<26)
		 			key_focus_flag-=12;	
		 		else if(key_focus_flag==26)
		 			key_focus_flag=14;	 		
		 		else if(key_focus_flag<39)
		 			key_focus_flag-=13;
		 		else if(key_focus_flag==39)
		 			key_focus_flag=26;
		 		else if(key_focus_flag<51)
		 			key_focus_flag-=12;
		 		else if(key_focus_flag==51)
		 			key_focus_flag=39;
		 		else if(key_focus_flag==52)
		 			key_focus_flag=45;
		 		else 
		 			key_focus_flag=50;
		 			GetKeyBoardLose(hwnd);
		 			GetKeyBoardFocus(hwnd);
		 			pre_focus_flag=key_focus_flag;
		 		break;
		}
		// if( *key_value==UOP_8||*key_value==UOP_9||*key_value==UOP_MUTE)
		//	UpdateVolumeDisp(AWFindWinCtrlByName("KeyBoard_Vol"),ProcessVolume(*key_value),GPIO_MUTE_STATUS);	
		   
    *key_value=UOP_NOP;
    return 1 ;

}
INT32S KeyBoardCaptionOnShow(PHWND hwnd, INT32S lpParam)
{
	

	switch(key_menu_flag)
    {
    case ID_MENU_MANUAL_URL:
        if (menu_index_process == ID_INTERNET_YAHOO_SETTING)
            hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_YAHOO_URL;
		else if (menu_index_process == ID_INTERNET_GOOGLE_SETTING)
            hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_GOOGLE_URL;
		else if (menu_index_process == ID_INTERNET_FRAME_CHNL_SETTING)
			hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_FRAMECHANNEL_URL;
        break;

    case ID_MENU_MANUAL_PASSWORD:
        if (menu_index_process == ID_INTERNET_YAHOO_SETTING)
            {
            hwnd->draw_info[2].draw_pos_x=600;
            hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_YAHOO_PASSWORD;
		    }
		else if(menu_index_process==ID_INTERNET_GOOGLE_SETTING)
        	 {
        	 hwnd->draw_info[2].draw_pos_x=600;
        	 hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_GOOGLE_PASSWORD;	
			}
		else if (menu_index_process == ID_INTERNET_FRAME_CHNL_SETTING)
			{
			hwnd->draw_info[2].draw_pos_x=520;
			hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_FRAMECHANNEL_PASSWORD; 
			}
        break;

    case ID_MENU_MANUAL_SSID:
    case ID_MENU_MANUALLY_ENTER_SSID:
        	hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_SSID;
        	
            //if(output_point[0]!='\0')
            //    StringCutLink_ForCaption(caption_str,CAPTION_STR_25,0,0,output_point,2,width);
            //else
            //    UpdateSelectlistCaption(CAPTION_STR_14,width);
            //char_number = IW_ESSID_MAX_SIZE;
            break;
        case ID_MENU_MANUAL_WEP:
        case ID_MENU_SECURITY_WEP:
        	hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_WEP;
            // WEP key, can be either 5/13 ASCII, or 10/26 HEX
            //UpdateSelectlistCaption(CAPTION_STR_33,width);
            //char_number = 13 * 2;
            break ;     
        case ID_MENU_MANUAL_WPA:
        case ID_MENU_SECURITY_WPA:
        	hwnd->draw_info[2].draw_data = (INT32U)KEYBOARD_STR_ENTER_WPA;
           // UpdateSelectlistCaption(CAPTION_STR_34,width);
           //char_number = IW_ENCODING_TOKEN_MAX;
            break;    	 
        case ID_MENU_SET_FRAME_NAME:
        	
            //UpdateSelectlistCaption(CAPTION_STR_50,width);
            //char_number = KODAK_FRAME_NAME_LEN;
            break;
        default:
            break;      	
    }

    return 0 ;
}
INT32S KeyBoardCaptionOnPaint(PHWND hwnd, INT32S lpParam)
{
    #if 0	
    PIXELVAL color_bk; 
    color_bk=AWSetForeground(WHITE_COLOUR);
    hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 0);
    hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 1);
    hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0);
    AWSetForeground(color_bk);
    #endif
    return 0 ;
}
INT32S KeyControlBarOnPaint(PHWND hwnd, INT32S lpParam)
{
   	PIXELVAL old_color;
	INT8U i;
	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 0) ;
	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 1) ;
	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2) ;
	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
	hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 4) ;
	hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;	
	old_color = AWSetForeground(AW_BLACK_COLOR) ;
	for(i=0;i<55;i++)
	 {  
	 	if((key_caps_flag==0)&&(key_shift_flag==0))
	 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word[i]) ;
	 		else 
	 		  AWAsciiPrintf(word_pos_x[i], word_pos_y[GetPos_y(i)], key_word_caps[i]) ;
	 }
	 AWSetForeground(old_color) ;
    return 1 ;
}

INT32S WinKeyBoardOnShow(PHWND hwnd, INT32S lpParam)
{
	//SetDefaultSlideShowFlag(0);
	osdsettpval(4,0xf);
	return 0;
}

INT32S WinKeyBoardOnHide(PHWND hwnd, INT32S lpParam)
{
	//SetDefaultSlideShowFlag(1);
	return 0;
}
#endif
